<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="/public/hui/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/public/hui/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/public/hui/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/public/hui/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/public/hui/static/h-ui.admin/css/style.css"/>
    <title>CI 后台框架系统 角色权限分配</title>
</head>
<body>
<header class="navbar-wrapper">
    <div class="navbar navbar-fixed-top">
        <div class="container-fluid cl"><a class="logo navbar-logo f-l mr-10 hidden-xs" href="/">H-ui.admin</a> <span
                    class="logo navbar-slogan f-l mr-10 hidden-xs">v3.0</span>
            <nav id="Hui-userbar" class="nav navbar-nav navbar-userbar hidden-xs">
                <ul class="cl">
                    <li>你好：</li>
                    <li class="dropDown dropDown_hover"><a href="#" class="dropDown_A"><?= $account; ?> <i
                                    class="Hui-iconfont">&#xe6d5;</i></a>
                        <ul class="dropDown-menu menu radius box-shadow">
                            <li><a href="/administrator">个人信息</a></li>
                            <li><a href="#">切换账户</a></li>
                            <li><a href="#">退出</a></li>
                        </ul>
                    </li>
                    <li id="Hui-msg"><a href="#" title="消息"><span class="badge badge-danger">1</span><i
                                    class="Hui-iconfont" style="font-size:18px">&#xe68a;</i></a></li>
                    <li id="Hui-skin" class="dropDown right dropDown_hover"><a href="javascript:;" class="dropDown_A"
                                                                               title="换肤"><i class="Hui-iconfont"
                                                                                             style="font-size:18px">&#xe62a;</i></a>
                        <ul class="dropDown-menu menu radius box-shadow">
                            <li><a href="javascript:;" data-val="default" title="默认（黑色）">默认（黑色）</a></li>
                            <li><a href="javascript:;" data-val="blue" title="蓝色">蓝色</a></li>
                            <li><a href="javascript:;" data-val="green" title="绿色">绿色</a></li>
                            <li><a href="javascript:;" data-val="red" title="红色">红色</a></li>
                            <li><a href="javascript:;" data-val="yellow" title="黄色">黄色</a></li>
                            <li><a href="javascript:;" data-val="orange" title="橙色">橙色</a></li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</header>
<aside class="Hui-aside">
    <div class="menu_dropdown bk_2">
        <? foreach ($menus as $k => $v): ?>
            <dl>
                <dt><i class="Hui-iconfont"><?= $v['m_icon'] ?></i> <?= $v['m_name'] ?><i
                            class="Hui-iconfont menu_dropdown-arrow">&#xe6d5;</i>
                </dt>
                <dd>
                    <ul>
                        <? foreach ($v['arr'] as $kk => $vv): ?>
                            <li class="<?= $vv['c_func']; ?>">
                                <a href="/<?= $vv['c_route'] ?>" title="系统设置"><?= $vv['c_name'] ?></a>
                            </li>
                        <? endforeach; ?>
                    </ul>
                </dd>
            </dl>
        <? endforeach; ?>
    </div>
</aside>
<div class="dislpayArrow hidden-xs"><a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a>
</div>
<section class="Hui-article-box" style="overflow:scroll">
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>
        首页
        <span class="c-gray en">&gt;</span>
        系统管理
        <span class="c-gray en">&gt;</span>
        角色分配权限
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>

    <div class="pd-20 text-l">
        <form class="layui-form" id="form">

            <? foreach ($list as $k => $v): ?>
            <div class="skin-minimal">
                <div class="check-box module_<?= $v['m_id'] ?>">
                    <input type="checkbox" id="module_<?=$v['m_id']?>" class="a" name="sub[<?= $k ?>][m_id]" value="<?=$v['m_id']?>" checked>
                    <label for="module_<?=$v['m_id']?>"><?=$v['m_name']?></label>
                </div>
                <div>
                    <? foreach ($v['arr'] as $kk => $vv): ?>
                        <div class="ml-30 mt-20">
                            <div class="skin-minimal">
                                <div class="check-box classify_<?=$vv['c_id']?>">
                                    <input type="checkbox" id="classify_<?= $vv['c_id'] ?>" class="b"
                                           name="sub[<?= $k ?>][arr][<?= $kk ?>][c_id]" value="<?= $vv['c_id'] ?>"
                                           <? if ($vv['is_check'] == 1): ?>checked <? endif; ?>>
                                    <label for="classify_<?= $vv['c_id'] ?>"><?= $vv['c_name'] ?></label>

                                    <div  style="display: flex;flex-wrap:wrap;align-content: center;">
                                    <? foreach ($vv['arr'] as $kkk => $vvv): ?>
                                            <div class="skin-minimal mt-10">
                                                <div class=" check-box authority_<?= $vvv['id'] ?>">
                                                    <input type="checkbox" id="authority_<?= $vvv['id'] ?>" class="c"
                                                           name="sub[<?= $k ?>][arr][<?= $kk ?>][arr][<?= $kkk ?>][authority_id]"
                                                           value="<?= $vvv['id'] ?>"
                                                           <? if ($vvv['is_check'] == 1): ?>checked <? endif; ?>>
                                                    <label for="authority_<?= $vvv['id'] ?>"><?= $vvv['name'] ?></label>
                                                </div>
                                        </div>
                                    <? endforeach; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <? endforeach; ?>
                </div>
                <? endforeach; ?>
            </div>

            <div class="mt-30" style="">
                <input type="hidden" name="role_id" value="<?=$role_id?>">
                    <input class="btn btn-primary radius ml-30" type="button" id="sub" value="提交">
                    <button  type="reset" id="reset" class="btn btn-default ml-30">重置</button>
            </div>
        </form>
    </div>
</section>

<script type="text/javascript" src="/public/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/public/lib/layer/layer.js"></script>
<script type="text/javascript" src="/public/hui/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="/public/hui/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="/public/admin.js"></script>
<script type="text/javascript">



/*
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    });
*/

    var menu = "<?=$function;?>";
    if (menu) {
        $('.' + menu).addClass('current').parent().addClass('opened').parent().addClass('open').before().addClass('selected');
        setTimeout(function () {
            $('.' + menu).parent().siblings('a').find('.nav_right').html('&#xe61a;');
        }, 100);
    }

    $("#reset").click(function(){
        $('input[type=checkbox]').prop('checked',false);
        return false;
    });

    $(".a").click(function(){
        //console.log($(this).get(0).checked);
        if(false === $(this).get(0).checked){
            $(this).parent().next().find('input').attr('disabled',true);
        }else{
            $(this).parent().next().find('input').attr('disabled',false);
        }
    });

    $(".b").click(function(){
        console.log($(this).nextAll('div'));

        if(false === $(this).get(0).checked){
            $(this).nextAll('div').find('input:checkbox').prop('checked',false);
        }else{
            $(this).nextAll('div').find('input:checkbox').prop('checked',true);
        }
    });


    $(".c").click(function(){
        var s = $(this).parent().parent().parent().children().length;//当前分类的所有权限列表数量
        var k = $(this).parent().parent().parent().find("input:checked").length;//当前分类已选择的权限数量

        if(0 === k){
            $(this).parent().parent().parent().prev().prev().prop('checked',false);//分类按钮
        }else{
            $(this).parent().parent().parent().prev().prev().prop('checked',true);//分类按钮
        }
    });

$("#sub").click(function(){
    $.ajax({
        dataType:'json',
        type: 'post',
        url: '/Systems/role_authority_do',
        data: $('#form').serialize(),
        success: function(data){
            if(1 == data){
                layer.msg('操作成功!', {
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){
                    window.location.href='/Systems/role';
                });
            }else if(999 == data){
                layer.msg('暂无权限!',{icon:4,time:1000});
            }else{
                layer.msg('操作失败!');
            }
        }
    });
});
</script>
</body>
</html>